package com.guigu.springcloud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping(value = "consumer")
public class ConsumerOrderController {

    public static final String SERVICE_URL = "http://nacos-payment-provider";

    private final RestTemplate restTemplate;

    public ConsumerOrderController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @GetMapping(value = "order/{id}")
    public String getOrder(@PathVariable("id") Integer id) {
        return restTemplate.getForObject(SERVICE_URL + "/payment/" + id, String.class);
    }
}